package com.hmilyylimh.cloud.xml.filter;

import org.apache.dubbo.rpc.*;
import org.apache.dubbo.rpc.support.RpcUtils;

import java.lang.reflect.Field;

public class DecryptProviderFilter implements Filter {
    /**
     * Always call invoker.invoke() in the implementation to hand over the request to the next filter node.
     *
     * @param invoker
     * @param invocation
     */
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        // 获取此次请求的类名、方法名，并且构建出一个唯一的 KEY
        String serviceName = invocation.getServiceModel().getServiceKey();
        String methodName = RpcUtils.getMethodName(invocation);
        String uniqueKey = String.join("_", serviceName, methodName);

        Object[] arguments = invocation.getArguments();
        for (Object obj:arguments){
            Class<?> aClass = obj.getClass();
            try {
                Field field = aClass.getDeclaredField("name");
                field.setAccessible(true);
                Object o = field.get(obj);

                field.set(obj,"132321112");
                System.out.println(o);
            } catch (Exception e) {
                e.printStackTrace();
            }


        }

        System.out.println("进入了过滤器......");

        return invoker.invoke(invocation);
    }
}
